package com.xpec.c4.service.module.task;

// import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;


/**
 * 
 * @author yangbingyan
 *
 */
public class TaskQueue {

	/**
	 * 
	 */
	ConcurrentLinkedQueue<TaskObject> queue = new ConcurrentLinkedQueue<TaskObject>();

	/**
	 * 
	 */
	// BlockingQueue<TaskObject> queue2 = new LinkedBlockingQueue<TaskObject>();
	
	
	/**
	 * Adds the specified element to the tail of this queue
	 * @param te
	 * @return
	 */
	public boolean add(TaskObject te){
		return queue.add(te);
	}
	
	public boolean isEmpty(){
		return queue.isEmpty();
	}
	
	/**
	 * Retrieves, but does not remove, the head of this queue, 
	 * returning null if this queue is empty.
	 * 
	 * @return
	 */
	public TaskObject peek(){
		return (queue != null) ? queue.peek() : null;
	}
	
	/**
	 * Retrieves and removes the head of this queue, or null if this queue is empty
	 * @return
	 */
	public TaskObject poll(){
		return (queue != null) ? queue.poll() : null;
	}	
	
	/**
	 * Removes a single instance of the specified element from this collection,
	 * if it is present (optional operation).
	 * @param te
	 * @return
	 */
	public boolean remove(TaskObject te){
		return (queue != null) ? queue.remove(te) : false;
	}
	
	/**
	 * Returns the number of elements in this queue.
	 * @return
	 */
	public int size(){
		return (queue != null) ? queue.size() : 0;
	}
	
	
	
}





